package com.it.data.network.interceptor;

import android.text.TextUtils;
import android.util.Log;

import com.tencent.mmkv.MMKV;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

import static com.it.data.manager.AppCacheManager.KEY_TOKEN;

/**
 * token拦截器
 */
public class TokenReqInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request.Builder builder = chain.request().newBuilder();
        String token = MMKV.defaultMMKV().decodeString(KEY_TOKEN);
        if (!TextUtils.isEmpty(token)) {
            builder.addHeader("token", token);
        }

        return chain.proceed(builder.build());
    }


}